<?php include '_init_.php';?>
<?php
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$dtFrame = new DataTable(constant('DB_TABLE_PHOTO_FRAME'));
$dtSize = new DataTable(constant('DB_TABLE_PHOTO_SIZE'));
$dtPrice = new DataTable(constant('DB_TABLE_PHOTO_FRAME_PRICE'));

$sizeList = $dtSize->get_list('','sort_index');
if($act == 'save')
{
	$framedata = $_REQUEST;
	if(intval($framedata['id']) < 1)
	{
		unset($framedata['id']);
	}
	$dtFrame->save($framedata);
	//save price
	$dtPrice->removeByCondition("`photo_frame_id`=".$framedata['id']);
	foreach($sizeList as $tmpData)
	{
		$priceData = array('photo_frame_id'=>$framedata['id'],'photo_size_id'=>$tmpData['id'],'price'=>floatVal($_REQUEST['size_id_'.$tmpData['id']]));
		$dtPrice->save($priceData);
	}
	AppMain::refreshParentFrame();
}
if($act == 'edit')
{
	$frameID = intval($_REQUEST['id']);
	$info = $dtFrame->get($frameID);
	$tmp_list = $dtPrice->get_list("`photo_frame_id`=".$frameID);
	$price_list = array();
	foreach($tmp_list as $tmpData)
	{
		$price_list[$tmpData['photo_size_id']] = $tmpData['price'];
	}
	$info['price'] = array();
	foreach($sizeList as $tmpData)
	{
		$info['price'][] = array('photo_size_id'=>$tmpData['id'],'name'=>$tmpData['name'],'price'=>$price_list[$tmpData['id']]);
	}
}
if($act == 'new')
{
	$info = array('id'=>'','name'=>'');
	$info['price'] = array();
	foreach($sizeList as $tmpData)
	{
		$info['price'][] = array('photo_size_id'=>$tmpData['id'],'name'=>$tmpData['name'],'price'=>'');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/formvalidate.js"></script>
</head>

<body>
<form method="post">
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="id" value="<?php echo $info['id'];?>"/>
<div class="mainf-8">
  <ul>
   <li class="article-1d">
     框號
    <input name="name" type="text" class="maine-keyina" value="<?php echo $info['name'];?>"/></li>
    <?php foreach($info['price'] as $tmpData):?>
    <li class="article-1e">
          <?php echo $tmpData['name'];?> $<input name="size_id_<?php echo $tmpData['photo_size_id'];?>" type="text"  class="maine-keyinf _validate_form_float" value="<?php echo $tmpData['price'];?>"/></li>
    <?php endforeach;?>
  </ul>

</div>
<div class="mainf-7">
<ul>
<li class="article-1g"><input name="" type="button" class="article-1a_btn" value="儲存" onclick="this.form.submit();"/></li>
</ul>
</div>
</form>
</body>
</html>
